from  flask import Blueprint,request
from app.utils.dbFunc import MySQLClinet as mysql
from app.utils.responseFunc import resultMsg

homebp = Blueprint("home",__name__,url_prefix="/testRunner")

@homebp.route("/login",methods=["post"])
def login():
    body = request.get_json()
    account = body.get("username")
    password = body.get("password")

    sql = "select id,account,realName userName from tb_system_user where account = '{}' and password = '{}';".format(account,password)
    dbRes = mysql().query(sql)
    if len(dbRes) == 0:
        return  resultMsg(code=0,msg="账号或者密码错误")
    token = "asjhdaskdjasisdkfdsnfis"
    data = dbRes[0]
    data.update(token=token)
    return resultMsg(msg="登录成功",data=data)
    